package com.dididoctor.doctor.Activity.Usercentre.MyPurse.CollectionMethods;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.dididoctor.doctor.MV.adapter.CommonAdapter;
import com.dididoctor.doctor.MV.adapter.ViewHolder;
import com.dididoctor.doctor.R;
import com.dididoctor.doctor.Utils.LoaderImage;
import com.dididoctor.doctor.Utils.Util;

import java.util.List;

/**
 * @version 2.0
 * @类描述：
 * @项目名称：ddgh
 * @类名称： OrderAdapter
 * @包名称： com.dididoctor.doctor.Activity.Order
 * @创建人： zhanjunjie
 * @创建时间：2016/4/20 18:43
 * @修改人：
 * @修改时间：2016/4/20 18:43
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class CollectionMethodsAdapter extends CommonAdapter<BankBean> {
    private List<BankBean> datas;
    private LoaderImage loaderImage;


    public CollectionMethodsAdapter(Context context, List<BankBean> datas) {
        super(context, datas, R.layout.item_collection_methods);
        this.context = context;
        this.datas = datas;
        loaderImage = new LoaderImage(context);
    }

    @Override
    public void convert(final int position, ViewHolder helper, final BankBean item) {
        //银行
        String bankName = item.getBankName();
        ImageView logo = helper.getView(R.id.iv_banklogo);
        if (!Util.isEmpty(bankName)) {
            helper.setText(R.id.tv_bankname, bankName);

            if (bankName.equals("光大银行")){
                logo.setImageResource(R.drawable.logo_gd);
            }else if (bankName.equals("建设银行")){
                logo.setImageResource(R.drawable.logo_js);
            }else if (bankName.equals("农业银行")){
                logo.setImageResource(R.drawable.logo_zn);
            }else if (bankName.equals("广东发展银行")){
                logo.setImageResource(R.drawable.logo_gf);
            }else if (bankName.equals("交通银行")){
                logo.setImageResource(R.drawable.logo_jt);
            }else if (bankName.equals("上海浦东发展银行")){
                logo.setImageResource(R.drawable.logo_pf);
            }else if (bankName.equals("兴业银行")){
                logo.setImageResource(R.drawable.logo_xy);
            }else if (bankName.equals("中国工商银行")){
                logo.setImageResource(R.drawable.logo_gh);
            }else if (bankName.equals("中国民生银行")){
                logo.setImageResource(R.drawable.logo_ms);
            }else if (bankName.equals("中国人民银行")){
                logo.setImageResource(R.drawable.logo_rm);
            }else if (bankName.equals("中国银行")){
                logo.setImageResource(R.drawable.logo_zy);
            }else if (bankName.equals("中国邮政")){
                logo.setImageResource(R.drawable.logo_yz);
            }else if (bankName.equals("招商银行")){
                logo.setImageResource(R.drawable.logo_zs);
            }
        }

        String bankNum = item.getBankId();
        if (!Util.isEmpty(bankNum)) {
            helper.setText(R.id.tv_cardnumber, bankNum);
        }

//        String picUrl = item.getPicUrl();
//        if (!Util.isEmpty(picUrl)) {
//            ImageView imageView = helper.getView(R.id.iv_banklogo);
//            loaderImage.load(imageView, picUrl);
//        }

        LinearLayout mLayBank = helper.getView(R.id.lay_bg);
        String bgColor = item.getColor();
        if (bgColor.equals("red")) {
            mLayBank.setBackgroundResource(R.drawable.bank_red);
        }
        if (bgColor.equals("purple")) {
            mLayBank.setBackgroundResource(R.drawable.bank_purple);
        }
        if (bgColor.equals("blue")) {
            mLayBank.setBackgroundResource(R.drawable.bank_blue);
        }
        if (bgColor.equals("green")) {
            mLayBank.setBackgroundResource(R.drawable.bank_green);
        }


        ImageView mIvPoint = helper.getView(R.id.iv_point);
        if (item.isEditor()) {
            mIvPoint.setVisibility(View.VISIBLE);
        }

        if (item.isChoice()) {
            mIvPoint.setBackgroundResource(R.drawable.point_bank_ischoice);
        } else {
            mIvPoint.setBackgroundResource(R.drawable.point_bank);
        }

        if (item.isEditor()) {
            mIvPoint.setVisibility(View.VISIBLE);
        } else {
            mIvPoint.setVisibility(View.GONE);
        }

            helper.getView(R.id.iv_point).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ((CollectionMethodsView)context).updateData(position);
                }
            });

    }
}
